#include "thread.h"
#include "cv.h"

volatile bool show_video = false;
static result_t result;
static HANDLE lock;

HANDLE create_thread(void)
{
    lock = CreateMutex(NULL, false, NULL);
    HANDLE h_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)cv_main,
                                   NULL, 0, NULL);
    return h_thread;
}

void get_result(result_t *ret)
{
    WaitForSingleObject(lock, INFINITE);
    *ret = result;
    ReleaseMutex(lock);
}

void set_result(const result_t* const ret)
{
    WaitForSingleObject(lock, INFINITE);
    result = *ret;
    ReleaseMutex(lock);
}
